package com.loadmore.common.base

import android.view.View
import android.view.ViewGroup
import androidx.appcompat.widget.Toolbar
import com.loadmore.common.R
import com.scwang.smartrefresh.layout.api.RefreshLayout
import com.scwang.smartrefresh.layout.listener.OnLoadMoreListener
import com.scwang.smartrefresh.layout.listener.OnRefreshListener
import kotlinx.android.synthetic.main.activity_base.*


/**
 *@author sunleilei
 *@date 2018/7/12
 *@time 8:01
 *
 */
open class BaseActivity : BaseFragmentActivity(), OnRefreshListener, OnLoadMoreListener {

    private var showNavigationIcon = true
    protected lateinit var actionBar: Toolbar

    override fun setContentView(layoutResID: Int) {
        var contentView:ViewGroup = layoutInflater.inflate(layoutResID,null) as ViewGroup
        setContentView(contentView)
        refreshLayout.setEnableRefresh(false)
        refreshLayout.setEnableLoadMore(false)
        refreshLayout.setOnRefreshListener(this)
        refreshLayout.setOnLoadMoreListener(this)
    }

    override fun setContentView(view: View?) {
        var contentView:ViewGroup = layoutInflater.inflate(R.layout.activity_base,null) as ViewGroup
        var contentContainer:ViewGroup = contentView.findViewById(R.id.content_container)
        actionBar = contentView.findViewById(R.id.actionBar)
        if (showNavigationIcon) {
            actionBar.setNavigationIcon(R.mipmap.icon_back)
            actionBar.navigationContentDescription = "返回"
        }
        setSupportActionBar(actionBar)
        contentContainer.addView(view, ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,ViewGroup.LayoutParams.MATCH_PARENT))
        super.setContentView(contentView)
        actionBar.setNavigationOnClickListener {
            finish()
        }
    }

    public fun setRefreshEnable(boolean: Boolean) {
        refreshLayout.setEnableRefresh(boolean)
    }

    public fun setLoadEnable(boolean: Boolean) {
        refreshLayout.setEnableLoadMore(boolean)
    }

    public fun hideNavigationIcon() {
       showNavigationIcon = false
    }

    public fun hideActionBar() {
        actionBar.visibility = View.GONE
    }

    public fun actionBarTitle(title:String) {
        //actionBar.setCenterTitle(title)
    }


    override fun onLoadMore(refreshLayout: RefreshLayout) {
    }

    override fun onRefresh(refreshLayout: RefreshLayout) {
    }
}